<template>
    <div>
        <el-container>
            <el-header>
                <Nav></Nav>
            </el-header>
            <el-main>
                <div class="content">
                    <el-form label-width="100px" :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
                        <el-form-item label="题图" prop="title">
                            <el-upload
                                    class="upload-demo"
                                    drag
                                    action="https://jsonplaceholder.typicode.com/posts/"
                                    multiple>
                                <i class="el-icon-upload"></i>
                                <div class="el-upload__text"><em>上传题图,让专栏获取更多关注</em></div>
                            </el-upload>
                        </el-form-item>
                        <el-form-item label="专栏名称" prop="title">
                            <el-input v-model="ruleForm.name" style="width: 360px"></el-input>
                        </el-form-item>
                        <el-form-item label="描述" prop="title">
                            <el-input type="textarea" rows="3"
                                      v-model="ruleForm.title" style="width: 360px"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
                            <el-button @click="resetForm('ruleForm')">重置</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </el-main>
            <el-footer>备案号：冀ICP备19020033号</el-footer>
        </el-container>
    </div>
</template>

<script>
    import Nav from "../components/Nav";
    export default {
        name: "ColumnEdit",
        components: {Nav},
        data() {
            return {
                ruleForm: {
                    id: '',
                    title: '',
                },
                rules: {
                    title: [
                        { required: true, message: '请输入标题', trigger: 'blur' },
                        { min: 3, max: 25, message: '长度在 3 到 25 个字符', trigger: 'blur' }
                    ],
                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    // if (valid) {
                    //     const _this = this
                    //     this.$axios.post('/blog/edit', this.ruleForm, {
                    //         headers: {
                    //             "Authorization": localStorage.getItem("token")
                    //         }
                    //     }).then(res => {
                    //         console.log(res)
                    //         _this.$alert('操作成功', '提示', {
                    //             confirmButtonText: '确定',
                    //             callback: action => {
                    //                 _this.$router.push("/blogs")
                    //             }
                    //         });
                    //
                    //     })
                    // } else {
                    //     console.log('error submit!!');
                    //     return false;
                    // }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        created() {
            const _this = this
            var blog = {
                id: "1",
                title: "生活就像海洋，只有意志坚强的人才能到达彼岸",
            }
            _this.ruleForm.id = blog.id
            _this.ruleForm.title = blog.title
        }
    }
</script>

<style scoped>

    .el-header, .el-footer {
        background-color: white;
        color: #333;
        text-align: center;
        line-height: 60px;
    }

    .el-main{
        background-color: white;
        padding: 5px;
        margin: 5px auto;
        width: 1200px;
        text-align: center;
        min-height: 1200px;
    }
    .content{
        margin: 0 auto;
        width: 600px;
    }
</style>
